package com.sunjq.fetchdata.service;

import java.util.List;

import android.util.Log;

import com.sunjq.fetchdata.activity.FetchDataActivity;
import com.sunjq.fetchdata.dao.FetchDataWaiShiChuDao;
import com.sunjq.fetchdata.object.Notice;

public class WaiShiChuBackendServiceImpl implements Runnable {

	
	public WaiShiChuBackendServiceImpl(FetchDataService fds, FetchDataWaiShiChuDao fdwscd) {
		this.us = fds;
		this.fdwscd = fdwscd;
	}

	private FetchDataService us;

	private FetchDataWaiShiChuDao fdwscd;

	@Override
	public void run() {
		System.out.println("backend waishichu method running");
		while (us.isRunning()) {
			Log.d("WaiShiChuBackendServiceImpl", "running backend service");
			List<Notice> noticeList = FetchDataActivity.pdwsc.buildData();
			for (Notice notice : noticeList) {
				System.out.println("all titles => " + notice.getTitle());
				System.out.println("all urls => " + notice.getDetailContentUrl());
				fdwscd.insert(notice);
			}

			try {
				Thread.sleep(1000 * 60 * 60 * 24);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.out.println("exception waishichu method running");
				this.us.setRunning(false);
			} finally {
				System.out.println("finally waishichu method running");
//				this.us.setRunning(false);
			}
		}

	}

}
